package com.shiguiwu.springboot3.controller;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageParam;
import com.shiguiwu.springboot3.dto.AuthUser;
import com.shiguiwu.springboot3.dto.request.CreateSessionReq;
import com.shiguiwu.springboot3.dto.request.SessionPageReq;
import com.shiguiwu.springboot3.dto.response.MySessionResponse;
import com.shiguiwu.springboot3.entity.ChatSession;
import com.shiguiwu.springboot3.service.ChatMessageService;
import com.shiguiwu.springboot3.service.ChatSessionService;
import com.shiguiwu.springboot3.service.MemberService;
import com.shiguiwu.springboot3.util.MemberContextUtils;
import com.shiguiwu.springboot3.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

/**
 * @description: 会员controller
 * @author: stone
 * @date: Created by 2025/9/24 21:10
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springboot3.controller
 */
@Tag(name = "会员接口", description = "会员信息接口")
@RestController
@RequestMapping("/member")
@Slf4j
public class MemberController {

    @Autowired
    private ChatSessionService chatSessionService;

    @Autowired
    private ChatMessageService chatMessageService;

    @Operation(summary = "获取用户", description = "获取用户接口")
    @GetMapping
    public R<AuthUser> getInfo() {
        log.info("获取当前会员信息");
        return R.ok(MemberContextUtils.getCurrentMember());
    }



    @Operation(summary = "创建会话", description = "创建会话接口")
    @PostMapping("/createSession")
    public R<Long> createSession(@RequestBody CreateSessionReq req) {
        return R.ok(chatSessionService.createSession(req));
    }

    @Operation(summary = "查询我的会话列表", description = "查询我的会话列表接口")
    @Parameters({
            @Parameter(name = "pageNum",description = "分页页数"),
            @Parameter(name = "pageSize",description = "分页大小")
    })
    @GetMapping("/mySession")
    public R<PageInfo<MySessionResponse>> mySessions(SessionPageReq req, PageParam pageParam) {
        return R.ok(chatSessionService.mySessions(req,pageParam));
    }

    @Operation(summary = "读取聊天信息", description = "读取聊天信息接口")
    @PostMapping("/read/{sessionId}")
    public R<Integer> read(@PathVariable Long sessionId) {
        return R.ok(chatMessageService.read(sessionId));
    }

}
